package com.example.innospace.demos.web.mapper;

import com.example.innospace.demos.pojo.dto.TeacherDTO;
import com.example.innospace.demos.pojo.dto.TeacherPageQueryDTO;
import com.example.innospace.demos.pojo.entity.Teacher;
import com.github.pagehelper.Page;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface TeacherMapper {
    @Select("select password from teacher where teacher_id=#{teacherId}")
    String getpassword(String teacherId);

    @Update("update teacher set password=#{newPassword} where teacher_id=#{teacherId}")
    void updatePassword(@Param("newPassword") String  newPassword,@Param("teacherId") String teacherId);

    @Select("select * from teacher where teacher_id=#{teacherId}")
    Teacher findById(String teacherId);

    @Insert("insert into teacher (teacher_id,name,phone_number,password,college,title,education_level,degree,avatar,status,email) values" +
            " (#{teacherId},#{name},#{phoneNumber},#{password},#{college},#{title},#{educationLevel},#{degree},#{avatar},#{status},#{email})")
    void insert(TeacherDTO teacherDTO);

    void batchDeleteById(@Param("teacherIds") List<String> teacherIds);

    void updateTeacherInfo(@Param(value = "teacherId")String teacherId, @Param(value = "teacher") Teacher teacher);
    @Update("update  teacher set status=#{status} where teacher_id=#{teacherId}")
    void teacherstartOrstop(@Param("status")Integer status,@Param("teacherId") String teacherId);

    Page<Teacher> pageQuery(TeacherPageQueryDTO teacherPageQueryDTO);

    @Update("update teacher set avatar=#{fileUrl} where teacher_id=#{teacherId}")
    void updateAvatar(@Param("teacherId") String teacherId, @Param("fileUrl") String fileUrl);

    @Select("select avatar from teacher where teacher_id=#{teacherId}")
    String getAvatar(String teacherId);

    @Update("update teacher set selected_project_id1=#{id}  where teacher_id=#{teacherId}")
    void setProjectId1(@Param("teacherId")String teacherId,@Param("id") Integer id);

    @Update("update teacher set selected_project_id2=#{id}  where teacher_id=#{teacherId}")
    void setProjectId2(@Param("teacherId")String teacherId,@Param("id") Integer id);


    @Select("select * from teacher where selected_project_id1=#{id} and selected_project_id2=#{id}")
    List<Teacher> findByProjectId(@Param("id")int id);



    @Update("update teacher set selected_project_id2=null where selected_project_id2=#{projectId}")
    void deleteByProject2(Integer projectId);
    @Update("update teacher set selected_project_id1=null where selected_project_id1=#{projectId}")
    void deleteByProject1(Integer projectId);
}
